<?php

namespace App\Transformers;

use App\Models\Collect;
use League\Fractal\TransformerAbstract;

class CollectTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['movies', 'follwers', 'author'];

    public function transform(Collect $collect)
    {
        return [
            'id' => $collect->id,
            'title' => $collect->title,
            'introduction' => $collect->introduction ?: '暂无介绍',
            'created_at' => $collect->created_at,
            'updated_at' => $collect->updated_at,
            'user_id' => $collect->user_id,
        ];
    }

    public function includeMovies(Collect $collect)
    {
        return $this->collection($collect->movies, new MovieTransformer());
    }
    public function includeAuthor(Collect $collect)
    {
        return $this->item($collect->author, new UserTransformer);
    }
}
